package com.hdu.hot100.hash;

import java.util.HashSet;
import java.util.Set;

public class lc128 {
    class Solution {
        public int longestConsecutive(int[] nums) {
            Set<Integer> set = new HashSet<>();
            for (int num : nums) {
                set.add(num);
            }
            int ans = Integer.MIN_VALUE;
            for (int i : nums)
            {
                if (!set.contains(i - 1))
                {
                    int cur = i;
                    int curLen = 1;
                    while (set.contains(cur + 1))
                    {
                        cur++;
                        curLen++;
                    }
                    ans = Math.max(ans, curLen);
                }
            }
            return ans == Integer.MIN_VALUE ? 0 : ans;
        }
    }
}
